home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Lib / include / dll.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-25  |  3.5 KB  |  110 lines

  1. /******************************************************************************
  2.  
  3.     MODULE
  4.     DLL.h
  5.  
  6.     DESCRIPTION
  7.     Header File for ``Double Linked Lists''
  8.  
  9.     NOTES
  10.     Okay - okay, such functions are also built
  11.     into the Kickstart, but this is a more
  12.     consistent interface, I hope ...
  13.  
  14.     We always have the concerned list as first argument
  15.     (also, if knowledge of the list is ignored inside the
  16.     function ...)
  17.  
  18.     HISTORY
  19.     13-11-94 b_noll created
  20.  
  21. ******************************************************************************/
  22.  
  23. #ifndef DLL_H
  24. #define DLL_H 1
  25.  
  26. /**************************************
  27.         Includes
  28. **************************************/
  29.  
  30. #ifndef   EXEC_TYPES_H
  31. #include <exec/types.h>
  32. #endif /* EXEC_TYPES_H */
  33.  
  34. /**************************************
  35.         Defines & Structures
  36. **************************************/
  37.  
  38. struct DNode {
  39.     struct DNode *Succ;
  40.     struct DNode *Pred;
  41. }; /* struct DNode */
  42.  
  43. struct DList {
  44.     struct DNode *Head;
  45.     struct DNode *Tail;
  46.     struct DNode *TailPred;
  47. }; /* struct DList */
  48.  
  49. /**************************************
  50.         Prototypes
  51. **************************************/
  52.  
  53. /* ---- Movement */
  54.  
  55. extern struct DNode *DLL_GetHead (struct DList *l);
  56. extern struct DNode *DLL_GetTail (struct DList *l);
  57. extern struct DNode *DLL_GetSucc (struct DList *l, struct DNode *n);
  58. extern struct DNode *DLL_GetPred (struct DList *l, struct DNode *n);
  59.  
  60. #define DLL_GetHead(l)                  ((APTR)     \
  61.     (((struct DList *)(l))->Head->Succ ?        \
  62.         ((struct DList *)(l))->Head : NULL ))
  63. #define DLL_GetTail(l)                  ((APTR)     \
  64.     (((struct DList *)(l))->TailPred->Succ ?    \
  65.         ((struct DList *)(l))->TailPred : NULL ))
  66. #define DLL_GetPred(l,n)                ((APTR)     \
  67.     (((struct DNode *)(n))->Pred->Pred ?        \
  68.         ((struct DNode *)(n))->Pred : NULL ))
  69. #define DLL_GetSucc(l,n)                ((APTR)     \
  70.     (((struct DNode *)(n))->Succ->Succ ?        \
  71.         ((struct DNode *)(n))->Succ : NULL ))
  72.  
  73.  
  74. /* ---- Construction and destruction */
  75.  
  76. extern void DLL_Init       (struct DList *l);
  77.  
  78. extern void DLL_AddHead     (struct DList *l, struct DNode *n);
  79. extern void DLL_AddTail     (struct DList *l, struct DNode *n);
  80. extern void DLL_AddInfront  (struct DList *l, struct DNode *n, struct DNode *pos);
  81. extern void DLL_AddBehind   (struct DList *l, struct DNode *n, struct DNode *pos);
  82.  
  83. extern void         DLL_Remove     (struct DList *l, struct DNode *n);
  84. extern struct DNode *DLL_RemHead    (struct DList *l);
  85. extern struct DNode *DLL_RemTail    (struct DList *l);
  86.  
  87. /* ---- Searching and scanning    */
  88.  
  89. extern void         DLL_Scan (struct DList *l, void (*scan)(struct DNode *, void *, int), void *userdata);
  90. extern struct DNode *DLL_Find (struct DList *l, int  (*find)(struct DNode *, void *, int), void *userdata);
  91.  
  92. /* ---- Indexing */
  93.  
  94. extern int         DLL_Length    (struct DList *l);
  95. extern struct DNode *DLL_NumToNode (struct DList *l, int num);
  96. extern int         DLL_NodeToNum (struct DList *l, struct DNode *n);
  97.  
  98. /* ---- BONUS: More complex structures */
  99.  
  100. extern void DLL_Sort        (struct DList *l, int (*comp)(struct DNode *, struct DNode *));
  101. extern void DLL_Filter        (struct DList *l, struct DList *dest, int (*check)(struct DNode *, void *), void *ud);
  102. extern void DLL_Join        (struct DList *dest, struct DList *add);
  103. extern void DLL_AddSorted    (struct DList *l, struct DNode *n, int (*comp)(struct DNode *, struct DNode *, void *), void *ud);
  104.  
  105. #endif /* !DLL_H */
  106.  
  107. /******************************************************************************
  108. *****  END DLL.h
  109. ******************************************************************************/
  110.